package com.boss.fileapp.dao.impl;

import com.boss.fileapp.consts.TableName;
import com.boss.fileapp.dao.ISalaryBasedataDao;
import com.boss.framework.dao.BaseDaoImpl;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Repository
public class SalaryBasedataDaoImpl extends BaseDaoImpl implements ISalaryBasedataDao {

    @Override
    public int selectSalaryItemCount(List<java.lang.String> salaryCodeList) {
        StringBuilder sb = new StringBuilder();
        List<Object> params = new ArrayList<>();
        sb.append(" select count(*) ")
                .append(" from ").append(TableName.SALARY_BASEDATA)
                .append(" where ")
                .append(" 1=1 ");
        if(!CollectionUtils.isEmpty(salaryCodeList)){
            sb.append(" and salary_code in ( ");
            for(String salaryCode : salaryCodeList){
                if(salaryCodeList.indexOf(salaryCode) != salaryCodeList.size() - 1){
                    sb.append(" ?, ");
                }else{
                    sb.append(" ?) ");
                }
                params.add(salaryCode);
            }
        }
        return super.getjdbcTemplate().queryForObject(sb.toString(), params.toArray(), int.class);
    }

    @Override
    public List<Map<String,Object>> selectSalaryCodeByProvince(String province) {
        List<String> params=new ArrayList<>();
        StringBuilder sb = new StringBuilder();
        sb.append(" select ").append(" salary_code,salary_name ")
                .append(" from ").append(TableName.SALARY_BASEDATA)
                .append(" where ").append(" salary_list_order is not null and mof_div_code = ? ")
                .append(" order by ").append(" salary_list_order ");
        params.add(province);
        return super.getjdbcTemplate().queryForList(sb.toString(), params.toArray());
    }
}
